//
//  CompanyView.m
//  Contacts
//
//  Created by 李 雷川 on 14-7-17.
//  Copyright (c) 2014年 李 雷川. All rights reserved.
//

#import "CompanyView.h"
#import "Contact.h"
#import "Company.h"

extern Contact *globalContact;
@implementation CompanyView
@synthesize logoImageView,companyLabel,companyPeopleLabel,peopleNumLabel;
@synthesize section,tableView;
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        self.backgroundColor = [UIColor whiteColor];
        
        UIImage *logoImage = [UIImage imageNamed:@"company_logo.png"];
        logoImageView = [[UIImageView alloc]initWithFrame:CGRectMake(15, 5,logoImage.size.width, logoImage.size.height)];
        logoImageView.image = logoImage;
        [self addSubview:logoImageView];
        
        companyLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(logoImageView.frame)+2, 5,CGRectGetWidth(self.frame), 14)];
        companyLabel.backgroundColor =[UIColor clearColor];
        companyLabel.font =[UIFont systemFontOfSize:14];
        [self addSubview:companyLabel];
        
        companyPeopleLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(logoImageView.frame)+2, CGRectGetMaxY(companyLabel.frame), 44, 24)];
        companyPeopleLabel.backgroundColor =[UIColor clearColor];
        companyPeopleLabel.font =[UIFont systemFontOfSize:10];
        companyPeopleLabel.textColor = [UIColor lightGrayColor];
        [self addSubview:companyPeopleLabel];
        companyPeopleLabel.text = @"单位人数:";
        
        
        peopleNumLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(companyPeopleLabel.frame)+2, CGRectGetMaxY(companyLabel.frame), 60, 24)];
        peopleNumLabel.backgroundColor =[UIColor clearColor];
        peopleNumLabel.font =[UIFont systemFontOfSize:10];
        peopleNumLabel.textColor = [UIColor lightGrayColor];
        [self addSubview:peopleNumLabel];
        [self initCompanyInfo];
      
    }
    return self;
}

-(void)initCompanyInfo{
    companyLabel.text= globalContact.company.name;
    peopleNumLabel.text =[NSString stringWithFormat:@"%ld",(long)globalContact.company.memberCount] ;
}

- (void)setFrame:(CGRect)frame{
    CGRect sectionRect = [self.tableView rectForSection:self.section];
    CGRect newFrame = CGRectMake(CGRectGetMinX(frame), CGRectGetMinY(sectionRect), CGRectGetWidth(frame), CGRectGetHeight(frame));
    [super setFrame:newFrame];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
